home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Ph 1.1.1 / PhClient / open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-01  |  3.3 KB  |  125 lines  |  [TEXT/MPS ]

  1. /*_____________________________________________________________________
  2.  
  3.       open.c - Open Ph Record Movable Modal Dialog.
  4. _____________________________________________________________________*/
  5.  
  6. #pragma load "precompile"
  7. #include "rez.h"
  8. #include "open.h"
  9. #include "utl.h"
  10. #include "glob.h"
  11. #include "oop.h"
  12. #include "wstm.h"
  13.  
  14. /*_____________________________________________________________________
  15.  
  16.     Global Variables.
  17. _____________________________________________________________________*/
  18.  
  19. static DialogPtr        Window;            /* ptr to dialog window */
  20.  
  21. static oop_Dispatch    dispatch = {
  22.                                 oop_DoPeriodic,
  23.                                 oop_DoClick,
  24.                                 open_DoKey,
  25.                                 oop_DoUpdate,
  26.                                 oop_DoActivate,
  27.                                 oop_DoDeactivate,
  28.                                 oop_DoGrow,
  29.                                 oop_DoZoom,
  30.                                 oop_DoClose,
  31.                                 open_DoCommand
  32.                             };
  33.  
  34. /*_____________________________________________________________________
  35.  
  36.     open_DoKey - Process a Key Down Event.
  37.     
  38.     Entry:    w = pointer to window record.
  39.                 key = ascii code of key.
  40.                 modifiers = modifiers from event record.
  41. _____________________________________________________________________*/
  42.  
  43. void open_DoKey (WindowPtr w, char key, short modifiers)
  44.  
  45. {
  46.     if (!glob_FilterAsciiChar(w, key, modifiers)) return;
  47.     oop_DoKey(w, key, modifiers);
  48. }
  49.  
  50. /*_____________________________________________________________________
  51.  
  52.     open_DoCommand - Process a Command.
  53.     
  54.     Entry:    w = pointer to window record.
  55.                 theMenu = menu index.
  56.                 theItem = item index.
  57. _____________________________________________________________________*/
  58.  
  59. Boolean open_DoCommand (WindowPtr w, short theMenu, short theItem)
  60.  
  61. {
  62.     if (theMenu == editID && theItem == pasteCmd &&
  63.         !glob_FilterPaste()) return true;
  64.     return oop_DoCommand(w, theMenu, theItem);
  65. }
  66.  
  67. /*_____________________________________________________________________
  68.  
  69.     InitField - Initialize Dialog Field.
  70.     
  71.     Entry:    fNum = field number.
  72.                 val = field value.
  73. _____________________________________________________________________*/
  74.  
  75. static void InitField (short fNum, Str255 val)
  76.  
  77. {
  78.     short            itemType;            /* item type */
  79.     Handle        item;                    /* handle to item */
  80.     Rect            box;                    /* item rect */
  81.  
  82.     GetDItem(Window, fNum, &itemType, &item, &box);
  83.     SetIText(item, val);
  84. }
  85.  
  86. /*_____________________________________________________________________
  87.  
  88.     open_DoDialog - Do open Dialog.
  89.     
  90.     Entry:    user = initial value for user field.
  91.     
  92.     Exit:        function result = true if canceled by user.
  93.                 user = alias or name.
  94. _____________________________________________________________________*/
  95.  
  96. Boolean open_DoDialog (Str255 user)
  97.  
  98. {
  99.     short         itemHit;        /* item hit */
  100.  
  101.     ShowCursor();
  102.     Window = wstm_Restore(true, openDlogID, nil, &OpenState);
  103.     utl_SetDialogText(Window, openUserField, user);
  104.     SelIText(Window, openUserField, 0, 0x7fff);
  105.     SetPort(Window);
  106.     TextFont(0);
  107.     TextSize(12);
  108.     oop_NewDialog(Window, openModal, nil, &dispatch, true, openOK, openCancel);
  109.     ShowWindow(Window);
  110.     while (true) {
  111.         oop_ClearWindItemHit(Window);
  112.         while (!(itemHit = oop_GetWindItemHit(Window)) && !Done) 
  113.             oop_DoEvent(nil, everyEvent, 
  114.                 oop_InForeground() ? shortSleep : longSleep, nil);
  115.         if (Done) itemHit = openCancel;
  116.         if (itemHit == openCancel) break;
  117.         break;
  118.     }
  119.     if (itemHit == openOK) utl_GetDialogText(Window, openUserField, user);
  120.     wstm_Save(Window, &OpenState);
  121.     oop_DoClose(Window);
  122.     InitCursor();
  123.     return itemHit == openCancel;
  124. }
  125.